const { tabs } = require('./src/mock')
const bodyParser = require('body-parser')

module.exports = {
  devServer: {
    before(app) {
      app.use(bodyParser.json())
      app.get('/api/tabs', (req, res) => {
        res.send({
          code: 200,
          data: tabs
        })
      })


      app.post('/api/detail', (req, res) => {
        const { id } = req.body;

        tabs.forEach(item => {
          let o = item.children.find(item => item.id === id)

          if(o) {
            res.send({
              code: 200,
              data: o
            })
          }
        })
      })
    }
  }
}